package com.yalu.service.data.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.yalu.dao.data.WarehousesareaDao;
import com.yalu.entity.base.BaseEntity;
import com.yalu.entity.data.Warehousesarea;
import com.yalu.entity.data.WarehousesareaKey;
import com.yalu.service.base.impl.BaseServiceImpl;
import com.yalu.service.data.WarehousesareaService;
import com.yalu.util.BaseUtil;

@Service
public class WarehousesareaServiceImpl extends BaseServiceImpl<Warehousesarea, WarehousesareaKey>
implements WarehousesareaService {

	@Resource
	private WarehousesareaDao warehousesareaDao;

	@Resource
	public void setBaseDao(WarehousesareaDao warehousesareaDao) {
		super.setBaseDao(warehousesareaDao);
	}

	@Override
	public int[] save(List<BaseEntity> entityList) {
		int[] returnCounts = new int[2];
		int saveCount = 0;
		int updateCount = 0;
		String time = BaseUtil.getTime();
		for(BaseEntity baseEntity : entityList){
			Warehousesarea entity = (Warehousesarea)baseEntity;
			WarehousesareaKey key  = entity.getWarehousesareaKey();
			Warehousesarea temp = warehousesareaDao.get(key);
			if(temp==null){
				entity.setCreatedt(time);
				warehousesareaDao.save(entity);
				saveCount++;
			}else{
				entity.setUpdatedt(time);
				BeanUtils.copyProperties(entity,temp, new String[] { "no", "isdeleted", "createdt",
						"createby", "updateby" });
				warehousesareaDao.update(temp);
				updateCount++;
			}
		}

		returnCounts[0] = saveCount;
		returnCounts[1] = updateCount;
		return returnCounts;
	}

}
